package com.thundersoft.phonecontact;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class CallItemActivity extends AppCompatActivity implements View.OnClickListener {

    private CollapsingToolbarLayout mToolbarLayout;
    private TextView mDetailNumber;
    private ImageButton mMakeCall;
    private ImageButton mMakeMsg;
    private CallItem mCallItem;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_item);
        mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
        Toolbar toolbar = (Toolbar) findViewById(R.id.itemToolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mDetailNumber = (TextView) findViewById(R.id.detail_activity_number_text_view);
        mMakeCall = (ImageButton) findViewById(R.id.image_button_call);
        mMakeMsg = (ImageButton) findViewById(R.id.image_button_msg);

        Intent intent=getIntent();
        mCallItem= (CallItem) intent.getSerializableExtra("key");
        if (mCallItem.getCachedName()==null){
            mToolbarLayout.setTitle(mCallItem.getCallNumber());
        }else{
            mToolbarLayout.setTitle(mCallItem.getCachedName());
        }
        mDetailNumber.setText(mCallItem.getCallNumber());
        mMakeCall.setOnClickListener(this);
        mMakeMsg.setOnClickListener(this);


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.image_button_call:
                MyFunction.makeCall(this,mCallItem.getCallNumber());
                break;
            case R.id.image_button_msg:
                MyFunction.makeMsg(this,mCallItem.getCallNumber());
                break;
        }
    }
}
